package com.schoolai.schoolsystem.feign;

import com.schoolai.entity.jpa.SysMenu;
import com.schoolai.entity.jpa.SysUser;
import com.schoolai.feign.system.IFeignSchoolSystemController;
import com.schoolai.schoolsystem.jpa.repository.SysUserRepository;
import com.schoolai.schoolsystem.service.IMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

/**
 * Copyright(C),2019-2025，XX公司
 * FileName:FeignSystemController
 * Author:bobby
 * 创建时间：2025/10/15 10:33
 * Description:feign调用系统信息的接口提供方
 * History:
 * <auth>        <time>       <version>       <desc>
 * 作者          修改时间       版本号         描述
 */
@RestController // 不要少了
public class FeignSystemController implements IFeignSchoolSystemController {
    @Autowired
    SysUserRepository sysUserRepository;
    @Autowired
    IMenuService menuService;
    @Override
    public SysUser loadUserByUsername(String username) {
        List<SysUser> list = sysUserRepository.findByUsername(username);
        if(list==null|| list.isEmpty()){
            return null;
        }
        // 通过jpa获得用户信息
        return list.get(0);
        //return sysUserService.search(username).get(0);
    }

    @Override
    public List<SysMenu> findMenuByUserId(String userId) {
        return menuService.findMenuByUserId(userId);
    }
}
